package com.example.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Emp;
import com.example.entity.R;
import com.example.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaozhang
 * @since 2024-10-17 09:24
 */
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private IEmpService empService;

    //分页
    @GetMapping("/page")
    public R page(@RequestParam(defaultValue = "1") Integer pageIndex,//页码  @RequestParam(defaultValue = "1")设置默认值
                  @RequestParam(defaultValue = "6") Integer pageSize,//每页显示的条数
                  String empName,String deptNo){
        Page<Emp> page = empService.lambdaQuery()
                .like(StringUtils.isNotEmpty(empName),Emp::getEname,empName)
                .eq(Objects.nonNull(deptNo),Emp::getDeptno,deptNo)
                .page(new Page<>(pageIndex,pageSize));

        long total = page.getTotal();
        List<Emp> list = page.getRecords();

        return R.page(total,list);

    }



}
